/*
 *     项目名称: Reactor服务模型-服务端
 *     文件名：epoll.cpp
 *     作者: 中国好青年(码农论坛)
 *      时间: 2024/9/4
 *                 
 * */
#include "EchoServer.h"
#include "util.h"
#include <signal.h>
#define ERROR 0
#define OK    1

#define DEBUG

#ifdef DEBUG
#define IP "192.168.174.140"
#define PORT 5005
#endif

/* 
 *     函数名: int main(int argc, char* argv[])
 *         返回值: int, 程序执行完返回值,正常返回0,一般不返回,执行错误返回-1
 *             参  数: int argc,传入参数个数; char* argv[],参数值
 *                 函数作用: 主函数入口  
 *                 */
EchoServer *echoserver;
TimeStamp s;

/* 退出函数 */
void stop(int sig);

int main(int argc, char* argv[])
{   
    info("%s %s","Welcome use EchoServer:",s.tostring().c_str());
    signal(2, stop);
    signal(15, stop);
#ifdef RELEASE
    if(argc != 3)
    {
        printf("usage: ./server.exe ip port\n");
        printf("example: ./server.exe 192.168.174.140 5005\n");
        return ERROR;
    }
#endif

#ifdef DEBUG
    echoserver = new EchoServer(IP, PORT, -1, 1, 1);
#else
    echoserver = new EchoServer(argv[1], atoi(argv[2]), -1, 1, 1);
#endif
    echoserver -> Start();
  
    return 0;
}

void stop(int sig)
{
    info("Exit(%d) Reactor %s", sig, s.tostring().c_str());
    echoserver -> Stop();
    delete echoserver;
    exit(0);
}

